import {ref} from 'vue'
import {defineStore} from 'pinia'

export const userTabStore = defineStore('tab',()=>{
    let navs =ref<any>([])

    let index =ref(0)

    const changeIndex = (current: number)=>{
        index.value = current;
    }

    const add =(option: any)=>{
        let current ;
        let isHas =navs.value.some((item: any,i:number)=>{
            if(item.name == option.name){
                current = i;
            }
            return item.name == option.name
        })
        if(!isHas){
            navs.value.push(option)
            index.value = navs.value.length -1;
        }
        else{
            if(current != undefined){
                changeIndex(current)
            }
        }
    }
    const remove = (i: number) => {
        navs.value.splice(i, 1)
      }

    const empty =()=>{
        navs.value = [];
    }

    return {
        navs,
        index,
        add,
        remove,
        changeIndex,
        empty
      }
})